#include <iostream>
#include <list>
#include <vector>
#include "tContainer_t.h"
using namespace std;

int main() {
	int *x;
	int y;

	tContainer_t<int, vector<int*>> container1;
	tContainer_t<int, vector<int*>> container2;
	cout << "Initiated container1 & container2. Current container is container1 (C to change)" << endl;

	tContainer_t<int, vector<int*>>* cur = &container1;


	while(1) {
		cout <<
			"\n| ChangeCurrent | empty | numelements | Insertend | fst | lst | Find | rmv | RmvAll | assign | get | = | merge | < | q: ";

		char c;
		cin >> c;

		if(c!='C' && c!='n' && c!='e' && c!='n' && c!='I' && c!='f'
			&& c!='l' && c!='F' && c!='r' && c!='R' && c!='a' && c!='g' && c!='=' && c!='m' && c!='q') {
				cout << "No such command. Try again (q to exit)." << endl;
				continue;
		}

		if (c == 'q') {
			break;
		}

		switch (c) {
		case 'C' :
			if (cur == &container1) {
				cout << "Current container is now container 2" << endl;
				cur = &container2;
			} else {
				cout << "Current container is now container 1" << endl;
				cur = &container1;
			}
			break;

		case 'e' :  
			cout << (cur->isEmpty() ? "Empty" : "Not Empty") << endl;
			break;

		case 'n' :  
			cout << "Number of elements: " << cur->getNumOfElem() << endl;
			break;

		case 'I' :
			x = new int;
			cout << "Please enter a number to insert at end:" << endl;
			cin >> *x;
			cur->insert(x);
			cout << "Inserted " << *x << " at the end of the container" << endl;
			break;

		case 'f' :  
			if (cur->getFirstElem() != 0) {
				cout << "First element is " << *cur->getFirstElem() << ". Pointer value: " << cur->getFirstElem() << endl;
			} else {
				cout << "No first element"  << endl;
			}
			break;

		case 'l' :  
			if (cur->getLastElem() != 0) {
				cout << "Last element is " << *cur->getLastElem() << ". Pointer value: " << cur->getLastElem() << endl;
			} else {
				cout << "No last element"  << endl;
			}
			break;

		case 'F' :
			cout << "Please enter a number to find: ";
			cin >> y;
			x = cur->find(y);
			if (x != 0) {
				cout << "Found element " << *x << ". Pointer value: " << x << endl;
			} else {
				cout << "Didn't find element " << y << endl;
			}
			break;

		case 'r' : 
			cout << "Please enter a number to remove: ";
			cin >> y;
			x = cur->removeElem(y);
			if (x != 0) {
				cout << "Successfully removed " << *x << ". Pointer value: " << x << endl;
			} else {
				cout << "Didn't find element " << y << endl;
			}
			break;

		case 'R' :
			cur->removeAll();
			cout << "Removed all elements" << endl;
			break;

		case 'm' :
			if (cur == &container1) {
				container1 += container2;
				cout << "Merged container 2 to container 1" << endl;
			} else {
				container2 += container1;
				cout << "Merged container 1 to container 2" << endl;
			}
			break;

		case '=' :
			if (cur == &container1) {
				container1 = container2;
				cout << "Assigned container 2 to container 1" << endl;
			} else {
				container2 = container1;
				cout << "Assigned container 1 to container 2" << endl;
			}
			break;

		case 'a' :
			x = new int;
			cout << "Please enter a number and index to put it in" << endl;
			cin >> *x >> y;
			try{
				(*cur)[y] = x;
			}catch(const char* ex) {
				cout << ex << endl;
				break;
			}
			cout << "Successfully assigned " << *x << " to index " << y << endl;
			break;

		case 'g' :
			cout << "Please enter an index to get from" << endl;
			cin >> y;
			try{
				x = (*cur)[y];
			}catch(const char* ex) {
				cout << ex << endl;
				break;
			}
			cout << "Element is " << *x << " (at index " << y  << ")" << endl;
			break;
		}
	}

	return 0;
}